﻿
namespace Jhong.FunMVC
{
    using System.IO;

    public sealed class HttpPostedFile
    {
        public string FileName { get; private set; }

        public string ContentType { get; private set; }

        public byte[] Data { get; private set; }


        public int ContentLength
        {
            get
            {
                return this.Data.Length;
            }
        }

        internal HttpPostedFile(string fileName, string contentType, byte[] data)
        {
            this.FileName = fileName;
            this.Data = data;
            this.ContentType = contentType;
        }

        public void SaveAs(string filePath)
        {
            using (var fileStream = new FileStream(filePath, FileMode.Create))
            {
                fileStream.Write(this.Data, 0, this.ContentLength);
            }
        }
    }
}